#include "Cargo.h"



Cargo::Cargo(const CargoDefine *define):
    define(define),
    object_qt(null)
{

}
Cargo::~Cargo() {
    if(object_qt){
        object_qt->scene()->removeItem(object_qt);
        delete object_qt;
        object_qt = null;
    }
}
void Cargo::obj_moveTo(double x, double y,gate::GateDirection dir){
    if(!object_qt) {return;}
    double dx = - CARGO_SHOW_LENTH / 2.0, dy = - CARGO_SHOW_LENTH / 2.0;
    switch(dir){
    case gate::Gate_UP:
        dx += BOX_LENTH / 2.0 ;
        break;
    case gate::Gate_RIGHT:
        dx += BOX_LENTH;
        dy += BOX_LENTH / 2.0 ;
        break;
    case gate::Gate_DOWN:
        dx += BOX_LENTH / 2.0;
        dy += BOX_LENTH;
        break;
    case gate::Gate_LEFT:
        dy += BOX_LENTH / 2.0;
        break;
    default:
        std:: cerr << "undefined gateDirection";
        break;
    }
    object_qt->setOffset(x*BOX_LENTH+dx,y*BOX_LENTH+dy);
}
inline bool Cargo::is_Divisble(){
    return this->define->cargo_type == CargoType::SHAPE;
}
CargoDefine::CargoDefine() : CargoDefine(CargoType::NONE) {}
CargoDefine::CargoDefine(CargoType cargo_type) : cargo_type(cargo_type) {}
CargoDefine::~CargoDefine() { ; }
#if IS_TEST > 0
int main(){
    
}
#endif
